<template>
  <div class="content">
    <div
      class="title font-16 font-bold"
      v-text="$t('label181')"
    ></div>
    <div class="table-wrap">
      <div class="filter-bar flex flex-v-center flex-between">
        <div class="flex">
          <p>{{$t('label229')}}：<span class="color-danger font-bold">{{myVipInfo.name}}</span></p>
          <p class="m15">{{$t('label182')}}：<span class="color-danger font-bold">{{myVipInfo.discount*100+'%'}}</span></p>
        </div>
        <div>
          <el-button type="danger" size="small" @click="prorpForm = true">购买VIP等级</el-button>
        </div> 
        <!-- {{$t('label183')}}：<span class="color-danger font-bold">{{myVipInfo.upgrade*1}}</span>&nbsp;&nbsp; -->
        <!-- {{$t('label184')}}&nbsp;{{nextLevel}}&nbsp;{{$t('label185')}}：<span class="color-dander">{{upgradeAmount}}</span> -->
      </div>
      <el-table
        v-loading='showLoading'
        max-height='500'
        :data='orderDetailData'
      >
        <el-table-column
          :label='$t("label178")'
          prop='name'
        ></el-table-column>
        <el-table-column
          align='center'
          :label='$t("label182")'
        >
          <span slot-scope="data">
            {{data.row.discount*100+"%"}}
          </span>
        </el-table-column>
        <el-table-column
          align='right'
          :label='$t("label406")'
        ><span slot-scope="scope">
            {{scope.row.bt}}AR {{$t("label407")}} {{scope.row.usdt}}USDT </span>
        </el-table-column>
      </el-table>
    </div>
    <!-- 购买会员 -->
    <el-dialog title="购买会员升级" :visible.sync="prorpForm" width="30%">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="资金密码" prop="tradpwd">
          <el-input v-model="ruleForm.tradpwd" type="password" clearable></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="prorpForm = false">取 消</el-button>
        <el-button type="primary" @click="BuyVipBtn()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<style lang="scss" scoped>
.table-wrap {
  border: $default-border;
  border-bottom: none;
  .filter-bar {
    padding: 0 15px;
    @include textVcenter;
    border-bottom: $default-border;
    background-color: #fcfcfc;
    .el-input {
      width: 300px;
    }
  }
}
.title {
  margin-bottom: 25px;
}
.m15{margin-left: 15px;}
</style>
<script>
export default {
  data() {
    return {
      orderDetailData: [],
      myVipInfo: {},
      showLoading: false,
      prorpForm:false,
      ruleForm:{
        tradpwd:'',
      }
    };
  },
  computed: {
    nextLevel() {
      if (this.orderDetailData.length > 0) {
        let len = this.orderDetailData.length - 1;
        let last = this.orderDetailData[len].level;
        if (this.myVipInfo.level < last) {
          return `vip${this.myVipInfo.level * 1 + 1}`;
        }
      }
    },
    upgradeAmount() {
      if (this.orderDetailData.length > 0) {
        let len = this.orderDetailData.length - 1;
        let lastLevel = this.orderDetailData[len].level;
        if (this.myVipInfo.level < lastLevel) {
          let next = this.orderDetailData[this.myVipInfo.level * 1 + 1].upgrade;
          return `${next * 1 - this.myVipInfo.upgrade * 1} CNY`;
        }
      }
    }
  },
  mounted() {
    this.getVipinfo();
  },
  methods: {
    getVipinfo(){
      this.request(this.api.vipinfo).then(res => {
        try {
          this.orderDetailData = res.data.list;
          this.myVipInfo = res.data.info[0];
        } catch (err) {}
      })
    },
    searchCoin() {
      if (this.searchVal == "") {
        this.orderDetailData = this.orderDetailRawData;
        return false;
      }
      let result = [];
      this.orderDetailRawData.map(item => {
        if (
          item.coin &&
          item.coin.toLowerCase().indexOf(this.searchVal.toLowerCase()) != -1
        ) {
          result.push(item);
        }
      });
      this.orderDetailData = result;
    },
    BuyVipBtn(){
      if (this.ruleForm.tradpwd=='') {
        this.errMsg("fundPwdPlaceholder");
        return false;
      }
      this.request(this.api.buyvip,this.ruleForm).then(res => {
        if (res.code == "0") {
          this.$message({message: res.msg,type: 'success'});
          this.getVipinfo();
          this.prorpForm=false;
          this.ruleForm.tradpwd='';
        } else {
          this.errMsg(res.msg || "操作失败");
          this.prorpForm=false;
          this.ruleForm.tradpwd='';
        }
      });
    }
  }
};
</script>